﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using AgencyEntityLib.BaseEntity;
using Ecopsy.DataTier;
using Ecopsy.DataTier.SqlLibrary;

public partial class EmplList : System.Web.UI.Page
{
    public string GetAgencyId()
    {
        return AgencyID;

    }

    protected void Page_Load(object sender, EventArgs e)
    {
        AgencyEntityLib.Context.AgencyLib_GlobalConstants._getAgencyId = GetAgencyId;
        if (!IsPostBack)
        {
            MyDataBind();
        }
        
    }

    private string AgencyID { get { return Request.QueryString["AgencyID"]; } }

    private void MyDataBind()
    {
        EmployeeList.sqlLoadStatment ListLoadStatment = new EmployeeList.sqlLoadStatment();
        ListLoadStatment.ParamValueList_SearchOption = vPropertyOfList.Options.Value;
        ListLoadStatment.ParamValueList.Clear();
        ListLoadStatment.ParamValueList.Add(new vPropertyOfList.ParamListItem() { Param = string.Empty, Value = DepartmentID });                    
        EmployeeList list = new EmployeeList();
        list.SqlStatment = ListLoadStatment;
        list.Load();
        list .Reset ();
        grdEmployees.DataSource = list;
        grdEmployees.DataBind();

    }
    
    private string DepartmentID { get { return Request.QueryString["DepartmentID"]; } }
    
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        Employeer empl = new Employeer();
        empl.DepartmentId = DepartmentID;
        empl.FirstName = "Новый сотрудник";
        empl.Save();
        Response.Redirect("EmplEditor.aspx?ID=" + empl.ID  + "&DepartmentID=" + DepartmentID + "&AgencyID=" + AgencyID);
    }

    protected void LinkButton2_Click(object sender, EventArgs e)
    {
        LinkButton btn = (LinkButton)sender ;
        Response.Redirect("EmplEditor.aspx?ID=" + btn.CommandArgument + "&DepartmentID="+DepartmentID+"&AgencyID="+AgencyID );
    }
}
